package com.zrs.gmall.payment.service;

import com.zrs.gmall.payment.process.PayHandler;
import com.zrs.gmall.payment.process.factory.PaymentFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ZhaoRuiSheng
 * @create 2023/3/22 20:14
 */
@Service
public class PaymentService {

    @Autowired
    private PaymentFactory paymentFactory;

    /**
     * 处理各种支付方式
     * @param orderId
     * @param payType
     * @return
     */
    public void pay(Long orderId, String payType) {
        // TODO 以下代码违背了开闭原则 解决方式：适配器模式/策略模式
        /*if ("weixinPay".equals(payType)) {
            //调用微信支付相关api
        } else if ("aliPay".equals(payType)) {
            //调用支付宝支付相关api
        } else if ("jdPay".equals(payType)) {
            //调用京东支付相关api
        }*/

        PayHandler payHanderler = paymentFactory.getPayHandler(payType);
        payHanderler.createPayHtml(orderId);
        payHanderler.preferentialScheme();
    }
}
